;;;;;;;;;;;;;;;;;;;;;;;;;
;; init.el
;; 2013/03/25
;; by haikuan liu
;;;;;;;;;;;;;;;;;;;;;;;;

(global-linum-mode t)
(setq default-tab-width 2)
(setq-default indent-tabs-mode nil)
(setq default-directory "e:/develop/Racket")
;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq load-path
      (cons (expand-file-name "~/.emacs.d/lisp") load-path))

;;;; session.el ;;;;;;;;;;
(require 'session)
(add-hook 'after-init-hook 'session-initialize)

;;; desktop.el
(load "desktop") 
(desktop-load-default) 
(desktop-read)

;; ibuffer.el
(require 'ibuffer)
(global-set-key (kbd "C-x C-b") 'ibuffer)

(require 'package)
;;; either the stable version:

(push '("marmalade" . "http://marmalade-repo.org/packages/")
      package-archives)
(add-to-list 'package-archives
  '("melpa" . "https://melpa.org/packages/"))

(package-initialize)

;; ParEdit mode
(autoload 'paredit-mode "paredit"
  "Minor mode for pseudo-structurally editing Lisp code."
  t)

;;;;;;;;;;;;
;; Scheme 
;;;;;;;;;;;;

(require 'cmuscheme)
(setq scheme-program-name "racket")         ;; 如果用 Petite 就改成 "petite"


;; bypass the interactive question and start the default interpreter
(defun scheme-proc ()
  "Return the current Scheme process, starting one if necessary."
  (unless (and scheme-buffer
               (get-buffer scheme-buffer)
               (comint-check-proc scheme-buffer))
    (save-window-excursion
      (run-scheme scheme-program-name)))
  (or (scheme-get-process)
      (error "No current process. See variable `scheme-buffer'")))


(defun scheme-split-window ()
  (cond
   ((= 1 (count-windows))
    (delete-other-windows)
    (split-window-vertically (floor (* 0.68 (window-height))))
    (other-window 1)
    (switch-to-buffer "*scheme*")
    (other-window 1))
   ((not (find "*scheme*"
               (mapcar (lambda (w) (buffer-name (window-buffer w)))
                       (window-list))
               :test 'equal))
    (other-window 1)
    (switch-to-buffer "*scheme*")
    (other-window -1))))


(defun scheme-send-last-sexp-split-window ()
  (interactive)
  (scheme-split-window)
  (scheme-send-last-sexp))


(defun scheme-send-definition-split-window ()
  (interactive)
  (scheme-split-window)
  (scheme-send-definition))

(add-hook 'scheme-mode-hook
  (lambda ()
    (paredit-mode 1)
    (define-key scheme-mode-map (kbd "<f5>") 'scheme-send-last-sexp-split-window)
    (define-key scheme-mode-map (kbd "<f6>") 'scheme-send-definition-split-window)))

;; multi eshell
(load "multi-eshell")
(require 'multi-eshell)

;; evil: vim mode for emacs
(require 'evil)
(evil-mode 1)

;; neotree: nerdtree fork for emacs
(require 'neotree)
(global-set-key [f8] 'neotree-toggle)
